package com.cheyun.netsalev3.view

import android.content.Intent
import android.text.Editable
import android.text.InputType
import android.text.TextWatcher
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.databinding.ActivityForgetBinding
import com.cheyun.netsalev3.databinding.ActivityRegisterBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.viewmodel.ForgetActivityViewModel
import com.cheyun.netsalev3.viewmodel.RegisterActivityViewModel

class ForgetActivity : BaseActivity<ActivityForgetBinding>() {
    var to = ""
    override fun initContentView(): Int {
        return R.layout.activity_forget
    }
    override fun initViewModel(): ViewModel? {
        if(intent.hasExtra("to")) {
            to = intent.getStringExtra("to")
        }
        return ViewModelProviders.of(this).get(ForgetActivityViewModel::class.java)
    }


    override fun initData() {
        binding.viewModel?.showPwd?.observe(this, Observer { it ->
            val img = resources.getDrawable(if(it){R.drawable.mmxs_tb}else{R.drawable.mmgb_tb})
            binding.ivPwd.setImageDrawable(img)
            binding.etPwd.inputType = if(it) InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_NORMAL else InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
        })
        binding.viewModel?.showConfirmPwd?.observe(this, Observer { it ->
            val img = resources.getDrawable(if(it){R.drawable.mmxs_tb}else{R.drawable.mmgb_tb})
            binding.ivConfirmPwd.setImageDrawable(img)
            binding.etConfirmPwd.inputType = if(it) InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_NORMAL else InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
        })
        binding.viewModel?.showTime?.observe(this, Observer {
            if(it.equals("0")){
                binding.txtSendCode.text = "发送验证码>>"
            }else{
                binding.txtSendCode.text = it+"s"
            }
        })
    }


    override fun initView() {
        binding.viewModel?.activity = this
        binding.viewModel?.to = to
        binding.viewModel?.showPwd?.postValue(false)
        binding.viewModel?.showConfirmPwd?.postValue(false)

    }
}
